package cn.JHai.rbac.service.imp;


import cn.JHai.rbac.comm.CurrentUtil;
import cn.JHai.rbac.domain.Customertracehistory;
import cn.JHai.rbac.domain.Customertransfer;
import cn.JHai.rbac.domain.Employee;
import cn.JHai.rbac.mapper.CustomertracehistoryMapper;
import cn.JHai.rbac.query.PageResult;
import cn.JHai.rbac.query.QueryObject;
import cn.JHai.rbac.service.CustomerTraceHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CustomerTraceHistoryImp implements CustomerTraceHistoryService {


    @Autowired
    private CustomertracehistoryMapper customerTraceHistoryMapper;


    @Override
    public int saveOrUpdata(Customertracehistory customerTraceHistory, Long customer_id) {
        //是插入
        System.out.println(customerTraceHistory);
        if(customerTraceHistory.getId()==null){
            Employee current = CurrentUtil.getCurrent();

            customerTraceHistory.setCustomer_id(customer_id);
            customerTraceHistory.setInput_user_id(current.getId());
            System.out.println(customerTraceHistory);
            return customerTraceHistoryMapper.insert(customerTraceHistory);
        }else {
            //跟新
            return customerTraceHistoryMapper.updateByPrimaryKey(customerTraceHistory);
        }
    }

    @Override
    public List<Customertracehistory> findAll() {

        return customerTraceHistoryMapper.selectAll();
    }

    @Override
    public PageResult query(QueryObject queryObject) {

        //全局查询
        if(queryObject.getKeyword() == null || queryObject.getKeyword().equals("")){
            Long count = customerTraceHistoryMapper.selectForCount(queryObject);
            return new PageResult(queryObject.getCurrentPage(),queryObject.getPageSize(),customerTraceHistoryMapper.pageSelect(queryObject),count);
        }
        //关键字查询
        else{
            Long count = customerTraceHistoryMapper.selectForCountWithKeyword(queryObject);
            return new PageResult(queryObject.getCurrentPage(),queryObject.getPageSize(),customerTraceHistoryMapper.pageSelectWithKeyword(queryObject),count);
        }
    }




}
